package com.bawei.solr;

import java.io.IOException;
import java.util.UUID;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.SolrInputDocument;

public class SolrCloudTest {

	public static void main(String[] args) throws SolrServerException, IOException {
		//输入zookeeper的地址和端口
		CloudSolrClient client = new CloudSolrClient("192.168.220.128:2281");
		//collection得名字
		client.setDefaultCollection("collection1");
		
		SolrInputDocument doc = new SolrInputDocument();
		doc.addField("id", UUID.randomUUID().toString().replace("-", ""));
		doc.addField("name", "david cheung");
		client.add(doc);
		client.commit();
		client.optimize(false, false, 2);
		client.shutdown();
	}
}
